package com.ly.web.controller.erp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.CustomerUserEntity;
import com.ly.heart.service.ICustomerUserService;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

/**
 * 用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户Controller
 *
 * @author cxl
 * @date 2024-05-14
 */
@Api(value = "CustomerUser", tags = "用户、客户关联关系")
@RestController
@RequestMapping("/heart/CustomerUser")
public class CustomerUserController extends BaseController
{
    @Autowired
    private ICustomerUserService customerUserEntityService;

    /**
     * 查询用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户列表
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:list')")
    @GetMapping("/list")
    @ApiOperation("查询用户、客户关联关系")
    public TableDataInfo list(CustomerUserEntity customerUserEntity)
    {
        startPage();
        List<CustomerUserEntity> list = customerUserEntityService.selectCustomerUserEntityList(customerUserEntity);
        return getDataTable(list);
    }

    /**
     * 导出用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户列表
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:export')")
    @Log(title = "用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出用户、客户关联关系")
    public void export(HttpServletResponse response, CustomerUserEntity customerUserEntity)
    {
        List<CustomerUserEntity> list = customerUserEntityService.selectCustomerUserEntityList(customerUserEntity);
        ExcelUtil<CustomerUserEntity> util = new ExcelUtil<CustomerUserEntity>(CustomerUserEntity.class);
        util.exportExcel( list, "用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户数据");
    }

    /**
     * 获取用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户详细信息
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取用户、客户关联关系")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(customerUserEntityService.selectCustomerUserEntityById(id));
    }

    /**
     * 新增用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:add')")
    @Log(title = "用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增用户、客户关联关系")
    public AjaxResult add(@RequestBody CustomerUserEntity customerUserEntity)
    {
        return toAjax(customerUserEntityService.insertCustomerUserEntity(customerUserEntity));
    }

    /**
     * 修改用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:edit')")
    @Log(title = "用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改用户、客户关联关系")
    public AjaxResult edit(@RequestBody CustomerUserEntity customerUserEntity)
    {
        return toAjax(customerUserEntityService.updateCustomerUserEntity(customerUserEntity));
    }

    /**
     * 删除用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户
     */
    @PreAuthorize("@ss.hasPermi('heart:CustomerUser:remove')")
    @Log(title = "用户、客户关联关系；当提供商机/客户重复时，则可以共享同一个客户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除用户、客户关联关系")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(customerUserEntityService.deleteCustomerUserEntityByIds(ids));
    }
}
